package com.itheima.service.db.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.itheima.domain.db.soul.SoulQuestionOption;
import com.itheima.mapper.SoulQuestionOptionMapper;
import com.itheima.service.db.SoulQuestionOptionService;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Service
public class SoulQuestionOptionServiceImpl implements SoulQuestionOptionService {

    @Autowired
    SoulQuestionOptionMapper soulQuestionOptionMapper;

    @Override
    public List<SoulQuestionOption> findByQuestionId(String questionId) {
        QueryWrapper<SoulQuestionOption> qw = new QueryWrapper<>();
        qw.eq("question_id", questionId);

        return soulQuestionOptionMapper.selectList(qw);
    }

    @Override
    public int findScore(String questionId, String optionId) {
        QueryWrapper<SoulQuestionOption> qw = new QueryWrapper<>();
        qw.eq("question_id", questionId);
        qw.eq("id", optionId);
        return soulQuestionOptionMapper.selectOne(qw).getScore();
    }

    @Override
    public void save(SoulQuestionOption soulQuestionOption) {
        soulQuestionOptionMapper.insert(soulQuestionOption);
    }

    @Override
    public void deleteByQuestionId(Long questionId) {
        QueryWrapper<SoulQuestionOption> qw = new QueryWrapper<>();
        qw.eq("question_id", questionId);
        soulQuestionOptionMapper.delete(qw);
    }

    @Override
    public void update(SoulQuestionOption soulQuestionOption) {
        soulQuestionOptionMapper.insert(soulQuestionOption);
    }
}
